package com.hcy.rabbitruntimeapi.center.handler;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hcy.rabbitbasicmodel.common.MyWebSocketMessage;
import com.hcy.rabbitbasicmodel.dto.UploadOrderTrackPointsDTO;
import com.hcy.rabbitbasicmodel.enums.M_Code;
import com.hcy.rabbitbasicutils.utils.GaoDeUtils;
import com.hcy.rabbitbasicutils.utils.RedisUtils;
import com.hcy.rabbitruntimeapi.center.MessageHandler;
import com.hcy.rabbitruntimeapi.center.MyMessageHandler;
import com.hcy.rabbitruntimeapi.model.message.driver.UploadTrackPointsDTO;
import com.hcy.schedulingclient.client.SchedulingLocationClient;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;

/**
 * @Author huchenying
 * @Description
 * @Date 2021/12/15 19:28
 */
@MyMessageHandler(M_Code.DriverUploadOrderTrack)
@Component
public class DriverUploadOrderTrackHandler extends MessageHandler {

    Logger logger = LoggerFactory.getLogger(DriverUploadOrderTrackHandler.class);

    @Autowired
    SchedulingLocationClient schedulingLocationClient;
    @Autowired
    RedisUtils redisUtils;
    @Autowired
    GaoDeUtils gaoDeUtils;

    @Override
    public void handler(MyWebSocketMessage myWebSocketMessage) {
        logger.debug("DriverUploadOrderTrack start code -> [{}] , desc -> [{}]", myWebSocketMessage.getCode(), myWebSocketMessage.getDesc());
        try {
            //解析数据体
            Object data = myWebSocketMessage.getData();
            String s = JSON.toJSONString(data);
            JSONObject jsonObject = JSON.parseObject(s);
            Integer tid = jsonObject.getInteger("tid");
            Integer trid = jsonObject.getInteger("trid");
            JSONArray points = jsonObject.getJSONArray("points");
            //验证参数 ， 调用运力系统
            logger.info("解析结果 -> {}", ToStringBuilder.reflectionToString(points));
            gaoDeUtils.uploadTrackPoints(tid,trid,points);
        } catch (Exception e) {
            logger.warn("DriverUploadOrderTrackHandler处理异常！reason -> {}", ToStringBuilder.reflectionToString(e));
        }
    }
}
